using System;
using System.Runtime.InteropServices;

namespace Leap
{
	public class Finger : Pointable
	{
		public enum FingerJoint
		{
			JOINT_MCP,
			JOINT_PIP,
			JOINT_DIP,
			JOINT_TIP
		}

		public enum FingerType
		{
			TYPE_THUMB,
			TYPE_INDEX,
			TYPE_MIDDLE,
			TYPE_RING,
			TYPE_PINKY
		}

		private HandleRef swigCPtr;

		public FingerType Type => (FingerType)LeapPINVOKE.Finger_Type_get(swigCPtr);

		public new static Finger Invalid => new Finger(LeapPINVOKE.Finger_Invalid_get(), false);

		public Finger(IntPtr cPtr, bool cMemoryOwn)
			: base(LeapPINVOKE.Finger_SWIGUpcast(cPtr), cMemoryOwn)
		{
			swigCPtr = new HandleRef(this, cPtr);
		}

		public static HandleRef getCPtr(Finger obj)
		{
			return obj?.swigCPtr ?? new HandleRef(null, IntPtr.Zero);
		}

		~Finger()
		{
			Dispose();
		}

		public override void Dispose()
		{
			lock (this)
			{
				if (swigCPtr.Handle != IntPtr.Zero)
				{
					if (base.swigCMemOwn)
					{
						base.swigCMemOwn = false;
						LeapPINVOKE.delete_Finger(swigCPtr);
					}
					swigCPtr = new HandleRef(null, IntPtr.Zero);
				}
				GC.SuppressFinalize(this);
				base.Dispose();
			}
		}

		public Finger()
			: this(LeapPINVOKE.new_Finger__SWIG_0(), true)
		{
		}

		public Finger(Pointable arg0)
			: this(LeapPINVOKE.new_Finger__SWIG_1(Pointable.getCPtr(arg0)), true)
		{
			if (!LeapPINVOKE.SWIGPendingException.Pending)
			{
				return;
			}
			throw LeapPINVOKE.SWIGPendingException.Retrieve();
		}

		public Vector JointPosition(FingerJoint jointIx)
		{
			return new Vector(LeapPINVOKE.Finger_JointPosition(swigCPtr, (int)jointIx), true);
		}

		public Bone Bone(Bone.BoneType boneIx)
		{
			return new Bone(LeapPINVOKE.Finger_Bone(swigCPtr, (int)boneIx), true);
		}

		public override string ToString()
		{
			return LeapPINVOKE.Finger_ToString(swigCPtr);
		}
	}
}
